﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace Boggle.Dictionaries
{
	/// <summary>
	/// A dictionary which has a slow IsWord method. Used primarily for testing.
	/// </summary>
	public class SlowOptimisticDictionary : IBoggleDictionary
	{
		/// <summary>
		/// The time that this dictionary takes to decide that a string is a word.
		/// </summary>
		private readonly Int32 delayMs;
		
		/// <summary>
		/// Creates a new dictionary with the default delay of 10s.
		/// </summary>
		public SlowOptimisticDictionary() : this(10000) { }

		/// <summary>
		/// Creates a new dictionary with the specified delay.
		/// </summary>
		/// <param name="delayMs">The time taken in milliseconds to decide that a string is a word.</param>
		public SlowOptimisticDictionary(Int32 delayMs)
		{
			if (delayMs < 0)
			{
				throw new ArgumentOutOfRangeException("delayMs", "delayMs must be greater than or equal to 0");
			}

			this.delayMs = delayMs;
		}

		#region IBoggleDictionary Members

		/// <summary>
		/// Gets the name of this dictionary.
		/// </summary>
		public string Name
		{
			get { return "Slow Optimistic Dictionary"; }
		}

		/// <summary>
		/// Gets a description for this dictionary.
		/// </summary>
		public string Description
		{
			get { return "A dictionary that thinks everything's a word, but which takes a while to decide."; }
		}

		/// <summary>
		/// Gets that Define is not supported by this dictionary.
		/// </summary>
		public bool IsDefineSupported
		{
			get { return false; }
		}

		/// <summary>
		/// Determines whether the supplied string is a word or not.
		/// </summary>
		/// <param name="word">The word to check.</param>
		/// <returns>True, always.</returns>
		public bool IsWord(string word)
		{
			Thread.Sleep(delayMs);
			return true;
		}

		/// <summary>
		/// Not implemented in this dictionary.
		/// </summary>
		/// <param name="word">The word to define.</param>
		/// <returns>Always throws a NotImplementedException.</returns>
		public List<string> Define(string word)
		{
			throw new NotImplementedException();
		}

		#endregion
	}
}